import request from '@/utils/request'
import type { TeamMemberDto, SeatDto, AccountDetailDto, RechargeReqDto, ExpireCompanyDto, SalaryFailReasonDto } from './types'
import type { PageDto, PagesDto, PageReqDto } from '../types'
import type { RemoveFromTeamTypeCnEnum, RoleCnEnum } from '@/const/enum'

// 获取团队成员列表
export function getTeamMembersList(params: PageReqDto & {
    companyId: number
    searchText?: string
}): Promise<PageDto<TeamMemberDto>> {
    return request.get('/crm-prod/pay/pay-manager-user/get-team-members', {
        params
    })
}

// 修改团队成员
export function updatePayManagerUser(data: {
    id: number
    phone: string
    userId: number
    userName: string
}): Promise<string> {
    return request.put('/crm-prod/pay/pay-manager-user', data)
}

// 修改小程序角色 设置/取消管理员
export function setAdmin(data: {
    companyId: number
    userId: number
    type: 0 | 1  // 0 普通管理员  1 超级管理员
    isAdmin: number
}): Promise<string> {
    return request.post('/crm-prod/pay/pay-manager-user/set-admin', data)
}

// 修改pc端角色
export function setPcAdmin(data: {
    id: number
    isAdmin: number
}): Promise<string> {
    return request.post('/crm-prod/system/user/change-pc-user-role', data)
}

// 重置小程序密码
export function ressetMiniProgramPassword(data: {
    id: number
    password: string
    userType: '02'
}): Promise<string> {
    return request.put('/crm-prod/pay/pay-manager-user/resetPwd', data)
}

// 重置pc端密码
export function ressetPcPassword(data: {
    password: string
    saasUserId: number
}): Promise<string> {
    return request.put('/crm-prod/system/user/resetPwd', data)
}

// 禁止/允许登录
export function toggleLoginPcStatus(data: {
    status: number
    userId: number
}): Promise<string> {
    return request.put('/crm-prod/pay/pay-manager-user/change-login-pc-status', data)
}

// 设置/取消公司席位管理员
export function setSeatAdmin(data: {
    companyId: number
    isSeatAdmin: boolean
    userId: number
}): Promise<string> {
    return request.put('/crm-prod/pay/pay-manager-user/set-co-seat', data)
}

// 获取公司席位信息
export function getSeatInfo(params: {
    companyId: number
}): Promise<SeatDto> {
    return request.get('/crm-prod/pay/pay-company-seat/company-seat-info', {
        params
    })
}


// 获取发薪公司账户明细列表
export function getAccountList(params: PageReqDto &{
    companyId: number
    payMode?: number
    productType?: number
    type?: number
}): Promise<PageDto<AccountDetailDto>> {
    return request.get('/crm-prod/saas/note/saasCompany/query-account-details', {
        params
    })
}

// 充值
export function recharge(data: RechargeReqDto): Promise<string> {
    return request.post('/crm-prod/payAccount/rechargeRecord/recharge', data)
}

// 查询距离到期30年内企业列表
export function getSoonExpireCompanyList(params: PageReqDto & {
    searchText: string
}): Promise<PageDto<ExpireCompanyDto[]>> {
    return request.get('/crm-prod/crm/record/pay-remind-seven-days-due', {
        params
    })
}

// 查询已经到期7天内的企业列表
export function getExpireCompanyList(params: PageReqDto & {
    searchText: string
}): Promise<PageDto<ExpireCompanyDto[]>> {
    return request.get('/crm-prod/crm/record/pay-remind-out-seven-date', {
        params
    })
}

/**
 * 查询领薪失败列表
 * @param params 
 * @returns 
 */
export function getFailReasonList(params: PageReqDto & {
    idCardNo?: string
    phone?: string
    queryPayDate?: string
}): Promise<PageDto<SalaryFailReasonDto>> {
    return request.get('/crm-prod/pay/pay-payment-record/query-fail-reason', {
        params
    })
}

/**
 * 批量移除团队成员
 * @param data 
 * @returns 
 */
export function batchRemoveTeamMember(data: {
    operateType: RemoveFromTeamTypeCnEnum.移出团队 | RemoveFromTeamTypeCnEnum.注销账号
    ids: number[]
}): Promise<void> {
    return request.put('/crm-prod/pay/pay-manager-user/batch-remove-team-member', data)
}

/**
 * 单个移除团队成员
 * @param data 
 * @returns 
 */
export function removeTeamMember(data: {
    companyId: number
    userId: number
}): Promise<void> {
    return request.put('/crm-prod/pay-manager-user/remove-team-member', data)
}

/**
 * 新接口设置成员角色，不再分区小程序还是pc
 * @param data 
 * @returns 
 */
export function changeRole(data: {
    id: number
    isAdmin: RoleCnEnum
}): Promise<void> {
    return request.post('/crm-prod/pay/pay-manager-user/changeRole', data)
}


